/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package customTags;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Stack;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 *
 * @author ToanNhan
 */
public class PutTag extends SimpleTagSupport {
    private String name;
    private String content;
    private boolean direct;

    /**
     * Called by the container to invoke this tag. 
     * The implementation of this method is provided by the tag library developer,
     * and handles all tag processing, body iteration, etc.
     */
    @Override
    public void doTag() throws JspException {
        InsertTag parent = (InsertTag)this.getParent();
        Stack stack = parent.getStack();
        if (stack == null){
            throw new JspException("PutTag.doTag() : NO STACK");
        }
        Hashtable params = (Hashtable) stack.peek();
        if (params == null){
            throw new JspException("PutTag.doTag() : NO HASHTABLE");
        }

        ArrayList<PageParameter> array = (ArrayList<PageParameter>) params.get(name);
        if (array == null){
            array = new ArrayList<PageParameter>();
            params.put(name, array);
        }
        array.add(new PageParameter(content, direct));
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }    

    /**
     * @param content the content to set
     */
    public void setContent(String content) {
        this.content = content;
    }


    /**
     * @param direct the direct to set
     */
    public void setDirect(boolean direct) {
        this.direct = direct;
    }

}
